//引入axios实例
import request from "@/utils/request"

//一个完整的sku的类型
export interface SkuListItemType {
    id?: number;
    spuId?: number;
    price: number;
    skuName: string;
    skuDesc: string;
    weight: string;
    tmId?: number;
    category3Id: number | null;
    skuDefaultImg: string;
    isSale: number;
    createTime: string;
    skuImageList: skuImageListType | null;
    skuAttrValueList: skuAttrValueListType | null;
    skuSaleAttrValueList: skuSaleAttrValueListType | null;
}

//sku中图片列表的每一项类型
export interface skuImageItemType {
    id?: number;
    skuId?: number;
    imgName: string;
    imgUrl: string;
    spuImgId?: number;
    isDefault: string;
}

//sku中图片列表的类型
export type skuImageListType = skuImageItemType[]

//sku中属性值列表的每一项类型
export interface skuAttrValueItemType {
    id?: number;
    attrId?: number;
    valueId?: number;
    skuId?: number;
    attrName: string;
    valueName: string;
}

//sku中属性值列表的类型
export type skuAttrValueListType = skuAttrValueItemType[]

//sku中销售属性列表的每一项类型
export interface skuSaleAttrValueItemType {
    id?: number;
    skuId?: number;
    spuId?: number;
    saleAttrValueId?: number;
    saleAttrId?: number;
    saleAttrName: string;
    saleAttrValueName: string;
}

//sku中销售属性列表的类型
export type skuSaleAttrValueListType = skuSaleAttrValueItemType[]

//sku分页列表的类型
export interface SkuPageListType {
    total: number,
    size: number,
    current: number,
    searchCount: boolean,
    pages: number,
    records: SkuListItemType
}



//根据SpuId获取的Sku列表的完整类型
export type SkuListType = SkuListItemType[]

//1.根据skuId下架某个商品
export const requestCancelSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/cancelSale/${skuId}`)
}

//2. 根据skuId上架某个商品
export const requestOnSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/onSale/${skuId}`)
}

//3.根据skuId删除某个sku
export const requestDeleteSku = (skuId: number) => {
    return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`)
}

//4.根据SpuId获取它的Sku列表
export const requestFindBySpuId = (spuId: number) => {
    return request.get<any, SkuListType>(`/admin/product/findBySpuId/${spuId}`)
}

//5.根据SkuId获取它的详情信息
export const requestGetSkuById = (skuId: number) => {
    return request.get<any , SkuListItemType>(`/admin/product/getSkuById/${skuId}`)
}

//6.获取sku分页列表
export const requestSkuPageList = (page: number , limit: number) => {
    return request.get<any , SkuPageListType>(`/admin/product/list/${page}/${limit}`)
}

//7.新增sku
export const requestSaveSkuInfo = (skuInfo: SkuListItemType) => {
    return request.post<any , null>(`/admin/product/saveSkuInfo`)
}

